package auth;


import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author student
 */
@Path("authcheck")
public class AuthService {
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public String checkCredentials(UserCredentials c,@Context HttpServletRequest request){
        System.out.println("--- Check");
        try {
            request.logout();
            request.login(c.getUsername(), c.getPassword());
            if(request.isUserInRole("admin")){
                return "admin";
            }
            return "user";
        } catch (ServletException ex) {
            Logger.getLogger(AuthService.class.getName()).log(Level.SEVERE, null, ex);
            return "none";
        }
        
    }
}
